package com.max.cms0.web.contorller;

import com.max.cms0.result.Result;
import com.max.cms0.utils.UploadUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @BelongsProject: cms0
 * @BelongsPackage: com.max.cms0.web.contorller
 * @Author: MHN
 * @CreateTime: 2024-11-21  09:12
 * @Description: TODO
 * @Version: 1.0
 */
@Api(tags = "文件上传模块")
@Slf4j
@RestController
public class FileUploadController {
    @Autowired
    private UploadUtils uploadUtils;
    @ApiOperation("文件上传")
    //用户登录后才能上传，所以/auth下
    @PostMapping("/auth/upload")
    @SneakyThrows //帮助处理 编译时异常
    // @RequestPart 注解可以与 MultipartFile 类型的参数一起使用，以处理上传的文件
    public Result upload(@RequestPart MultipartFile img){
        return Result.success(uploadUtils.fileToOSS(img));
    }
}
